home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / DynaDoodle / Star.bproj / Star.m < prev   
Text File  |  1993-12-14  |  3KB  |  104 lines

  1. /**------------------------------------*------------------------------------**
  2.     RELEASED TO THE PUBLIC DOMAIN BY CODEWORKS DEVELOPMENT, DECEMBER 1993.
  3.     You may freely copy, distribute and reuse the code in this example. Codeworks disclaims any warranty of any kind, expressed or implied, as to its fitness for any particular use.
  4.     Author:  Andrew Vyrros, av@codeworks.com
  5.  **------------------------------------*------------------------------------**/
  6. /**------------------------------------*------------------------------------**
  7.     File:    Star.m
  8.     Project: DynaDoodle/Star.bproj
  9.     Info:    Implementation of the Star class.
  10.  **------------------------------------*------------------------------------**/
  11.  
  12. #import "Star.h"
  13. #import <appkit/appkit.h>
  14.  
  15.  
  16. #define NAME NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Star class]], "Name", "Star", "Name of Star Doodle")
  17. #define DESCRIPTION NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Star class]], "Description", "A multi-point star. You can change the number of points and the length of the points.", "Description of Star Doodle")
  18.  
  19.  
  20. @implementation Star
  21.  
  22.  
  23. - initFrame:(const NXRect *)f
  24. {
  25.   [super initFrame:f];
  26.   numPoints = 8;
  27.   pointRatio = 1.0;
  28.   troughRatio = 0.5;
  29.   return self;
  30. }
  31.  
  32.  
  33. - didLoadNib
  34. {
  35.   numPoints = [numPointsSlider intValue];
  36.   pointRatio = [pointRatioSlider floatValue];
  37.   troughRatio = [troughRatioSlider floatValue];
  38.   return self;
  39. }
  40.  
  41.  
  42. - drawSelf:(const NXRect *)rects :(int)rectCount
  43. {
  44.   float               theta, thetaStepD2;
  45.   NXPoint             center, p;
  46.   NXCoord             rPeak, rTrough;
  47.   int                 i;
  48.   
  49.   NXSetColor(backgroundColor);
  50.   NXRectFill(&bounds);
  51.   NXSetColor(foregroundColor);
  52.  
  53.   thetaStepD2 = (M_PI * 2) / numPoints / 2.0;
  54.   center.x = bounds.origin.x + bounds.size.width / 2.0;
  55.   center.y = bounds.origin.y + bounds.size.height / 2.0;
  56.   
  57.   rPeak = pointRatio * MIN(bounds.size.width, bounds.size.height) / 2.0;
  58.   rTrough = rPeak * troughRatio;
  59.  
  60.   theta = M_PI_2;
  61.   PSmoveto(center.x, center.y + rPeak);
  62.   i = numPoints;
  63.   while (i--)
  64.   {
  65.     theta -= thetaStepD2;
  66.     p.x = center.x + rTrough * cos(theta);
  67.     p.y = center.y + rTrough * sin(theta);
  68.     PSlineto(p.x, p.y);
  69.     theta -= thetaStepD2;
  70.     p.x = center.x + rPeak * cos(theta);
  71.     p.y = center.y + rPeak * sin(theta);
  72.     PSlineto(p.x, p.y);
  73.   }
  74.   PSfill();
  75.   return self;  
  76. }
  77.  
  78.  
  79. - takeNumPointsFrom:sender
  80. {
  81.   numPoints = [[sender selectedCell] intValue];
  82.   [self update];
  83.   return self;
  84. }
  85.  
  86.  
  87. - takePointRatioFrom:sender
  88. {
  89.   pointRatio = [[sender selectedCell] floatValue];
  90.   [self update];
  91.   return self;
  92. }
  93.  
  94.  
  95. - takeTroughRatioFrom:sender
  96. {
  97.   troughRatio = [[sender selectedCell] floatValue];
  98.   [self update];
  99.   return self;
  100. }
  101.  
  102.  
  103. @end
  104.